package com.study2.A03Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.TreeMap;

public class A01_Test {
    /*
    * 自动点名器
    *   班里有n个学生，实现随机点名
    * */
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十", "郑十一", "王十二", "李十三", "赵十四", "孙十五", "周十六", "吴十七", "郑十八", "王十九", "李二十", "赵二十");
        
        Random r = new Random();
        TreeMap<String,Integer> map = new TreeMap<>();
        for (int i = 0; i < 100; i++) {
            // 第一种
            /*String s = list.get(r.nextInt(list.size()));
            String name = s;
            System.out.println(s);
            if(map.containsKey(name)){
                int num = map.get(name) + 1;
                map.put(name,num);
            } else {
                map.put(name, 1);
            }*/
            
            // 第二种
            Collections.shuffle(list);
            String name = list.get(0);
            if(map.containsKey(name)){
                int num = map.get(name) + 1;
                map.put(name,num);
            } else {
                map.put(name, 1);
            }
        }
        
        map.forEach(
                (k,v) -> System.out.println(k + "-->" + v)
        );
    }
}
